import { Component, OnInit } from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/toPromise';


import { MyhttpService } from '../../services/myhttp.service';
import { UserService } from '../../services/user.service';
import { HttpService } from '../../services/http.service'; 
import { SessionService } from '../../services/session.service';
import { User } from '../../Entities/user.entity';

@Component({
  selector: 'app-home',
  providers: [MyhttpService,UserService,HttpService,SessionService],
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css'] 
})
export class HomeComponent implements OnInit {

   public alerts: Array<string> = [];
   constructor(private userService: UserService, private sessionService: SessionService, private httpService:HttpService,private http:Http,private myhttpService:MyhttpService) { }

  ngOnInit() {
    let user: User = new User();
     user.loginUserName = '13666666666';
     user.loginPwd = 'aibianli888';
     user.loginValidate = '455049';
     user.loginIsValidate = 0;
     this.userService.authenicate(user)
         .subscribe(
         response => this.loginOnSuccess(response),
         response => this.loginOnError(response));


      this.myhttpService.getcontacte().then((data)=>{
          // console.log(data)
        })



 }
    private loginOnSuccess(res: any) {
      localStorage.setItem("dapptoken",res.data.access_token);


 
        // this.router.navigate(['/home/error']);
    };
    private loginOnError(response: User) {      
      //  this.alertService.renderErrorMessage(response.returnMessage);
        // this.messageBox = this.alertService.returnFormattedMessage();
        // this.alerts = this.alertService.returnAlerts();
        // console.dir(response);
          
    }
}